import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
    IsNotEmpty,
    IsNumber,
    IsOptional,
    IsString,
    ValidateIf
} from 'class-validator';

export class CreateRoleDto {
    @IsString({
        message: '角色参数类型错误',
    })
    @IsNotEmpty({
        message: '角色名称不能为空',
    })
    @ApiProperty({ description: '角色名称' })
    name: string;

    @IsOptional()
    @IsString()
    @ApiPropertyOptional({ description: '角色备注' })
    remark: string;
}

export class RoleMenuActionDto {
    @IsNumber()
    @ApiProperty({ description: '角色ID' })
    roleId: number;

    @IsNumber()
    @ApiProperty({ description: '菜单ID' })
    menuId: number;

    @IsNumber()
    @ApiProperty({ description: '功能ID' })
    actionId: number;
}

export class RoleAuthConfigDto {
    @IsNumber(
        {},
        {
            message: 'roleId参数类型错误',
        },
    )
    @ApiProperty({ description: '角色ID' })
    roleId: number;

    @IsNumber(
        {},
        {
            message: 'menuId参数类型错误',
        },
    )
    @ValidateIf(o => o.menus.indexOf(o.menuId) > 0, {
        message: '当前菜单参数错误'
    })
    @ApiProperty({ description: '菜单ID' })
    menuId: number;

    @IsNumber(
        {},
        {
            each: true,
            message: 'menus参数错误',
        },
    )
    @ApiProperty({
        description: '授权给roleId的菜单ID数组', type: 'array', items: {
            type: 'number'
        }
    })
    menus: Array<number>;

    @IsNumber({}, { each: true, message: 'actions参数错误' })
    @ApiProperty({ description: '授权给roleId+menuId的功能ID数组', type: 'array', items: {
        type: 'number'
    } })
    actions: number[];
}

export class CreateUserDto {
    @IsString({
        message: '姓名参数错误'
    })
    @ApiProperty({description: '用户名称'})
    name: string;

    @IsString({
        message: '状态参数错误'
    })
    @ApiProperty({description: '用户状态 枚举值 在用、 停用' })
    status: string;

    cfs_id: number;

    @IsString()
    @IsOptional()
    @ApiProperty({ description: '用户备注'})
    remark: string;
}

export class RoleUserDto {
    @IsNumber({}, { message: '角色参数错误' })
    @ApiProperty({ description: '角色ID'})
    roleId: number;

    @IsNumber({}, { each: true, message: '用户参数错误' })
    @ApiProperty({ description: '用户ID', type: 'array', items: {
        type: 'number'
    }})
    userIds: number[];
}